Skip to content

bookkeeping: per-child mixed allocation classification (successor to #314) - #533

Draft
alexeygrigorev wants to merge 6 commits into
mainfrom
agent/pr314-successor-56e5d826
Draft

alexeygrigorev wants to merge 6 commits into
mainfrom
agent/pr314-successor-56e5d826

Conversation

@alexeygrigorev

@alexeygrigorev alexeygrigorev commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Successor to #314 (kept open and draft), on current main.

Fixes the mixed-allocation classification bug that survives on main: a payment with invoice allocations was classified on its parent (Taxes/mandatory/owner-draw markers), and children inherited the parent's markers. Now each child is classified on its own, parent-only markers are dropped from child projections, snapshot evidence is selected from the reportable children only, and the monthly archive lists the same rows.

Archive parity (backend/src/routes/bookkeepingReports.ts). The archive reloaded each snapshotted payment and wrote the parent row, so a mixed Software/Taxes payment shipped its full total next to only the Software child's documents. It now renders the snapshotted payments through the shared accountant rows (accountantReportRows plus the reportable filter, the selection the snapshot counts and the reconcile package exports): an allocated payment as its reportable children, with the child's label, amount, category, EUR value and VAT and the payment's dates, entry type and bank reference; any other payment as itself. The twelve-column format is unchanged (unsigned amount with entryType, quoted cells).

Snapshot storage is unchanged. The v2 ID lists (transactionIds, documentIds) stay on the report, nothing is migrated, and archive generation writes no ledger row or evidence document. An already archived report is served as stored.

Safety gates (409, before any write or S3 call). A snapshot whose payment has no reportable child any more (staleTransactionIds), or whose child has no EUR value, is refused instead of shipping evidence without a row.

The snapshot's missingEvidence warning follows the same evidence rule: an allocated child is evidenced by its own allocation document, not by a parent-level link.

Not ported (see the comment on #314): chunked v4 snapshots, CAS migration, and the VAT category exemption.

Tests (synthetic fixtures). backend/tests/bookkeeping-report-archive.test.ts reads the CSV back out of the generated ZIP: child totals, labels and order, the evidence list, payment direction, dates and cell format, an older ID-list report, and both refusals. Plus backend/tests/bookkeeping-reporting.test.ts and a case in backend/tests/api-bookkeeping.test.ts. The archive cases fail on 7e860c7 and pass on 201e25f. tsc is clean for the source, test and script configs.

… evidence from reportable children (successor to #314)
The snapshot counts and selects evidence per reportable child, but the
archive still reloaded each snapshotted payment and wrote the parent row,
so a mixed Software/Taxes payment shipped its full total with only the
Software child's documents.

The archive now renders its snapshotted payments through the same
accountant rows the snapshot and the reconcile package use: an allocated
payment as its reportable children (child label, amount, category, EUR and
VAT; the payment's dates, entry type and bank reference), any other payment
as itself. The stored snapshot stays a v2 ID list: nothing is migrated and
no ledger row or evidence document is written. An already archived report
is served as stored.

A snapshot whose payment has no reportable child any more, or whose child
has no EUR value, is refused before any write instead of shipping evidence
without a row.

The snapshot's missing-evidence warning follows the same evidence rule: an
allocated child is evidenced by its own allocation document, not by a
parent-level link.

Tests read the CSV back out of the generated ZIP.
@alexeygrigorev

alexeygrigorev commented Nov 26, 2026 •

Copy link
Copy Markdown
Member Author

Archive parity for the gap from the #314 review, on top of 7e860c7: 201e25f (this PR stays draft; nothing merged).

Reproduced on 7e860c7 with backend/tests/bookkeeping-report-archive.test.ts, which unzips the generated archive and parses datatalksclub-<month>.csv:

  • a mixed Software/Taxes payment and a Taxes/Software owner-draw payment each shipped one parent row with the parent total, counterparty and description (60.00 / 70.00 / 50.00 / 100.00 USD) beside only the reportable children's documents;
  • a snapshot whose payment had no reportable child, or whose child had no EUR value, still archived (201);
  • a bank-matched allocated payment raised a false missingEvidence warning (1 instead of 0), because children were checked against parent-level links.

Fixed in 201e25f

  • The archive renders its snapshotted payments through accountantReportRows + the reportable filter, the same selection the snapshot counts and the reconcile package exports. An allocated payment is listed as its reportable children in saved allocation order.
  • Payment direction, dates and format stay as contracted: unsigned amount with the payment's entryType, the payment's transactionDate/paidDate and statementRef on every child (never the allocation's own invoice dates), the child's own amountEur/vatAmount (the parent's VAT total is never copied), twelve quoted columns, LF endings.
  • Storage is unchanged: v2 ID lists, no migration, no write to a ledger row or evidence document while archiving. Transaction and document references stay on the report. An already archived report is served as stored.
  • Both refusals return 409 before any write, S3 read or signing.
  • missingEvidence uses the child evidence rule.

Verification (targeted only, no bulk reruns)

Trade-offs and residuals

…ldren

The package preview classified and counted on the parent payment, so a
mixed Software/Taxes payment showed one row with the parent total and the
payment's own links as evidence, while the package the snapshot builds
lists its reportable children and their allocation documents.

The preview now selects rows the way the snapshot does: a payment with
saved invoice allocations as its reportable children, each kept in or out
on its own category and text, never on the payment's markers; any other
entry as itself under the surface's rule. An ordinary entry is evidenced by
its links and a child by its own allocation document, so links of an
allocated payment no longer count as evidence. The EUR preflight runs on
the reportable children: a converted payment with an unconverted child
blocks the package, as the snapshot's 409 does.

An entry without complete allocations previews exactly as before. Nothing
is written: snapshots, the archive and ledger rows are untouched.
@alexeygrigorev

Copy link
Copy Markdown
Member Author

Backlog triage 2026-11-27, status check (no merge by the triage session — this stays the owner's draft):

  • Scope as described in this thread is complete in the branch: per-child classification (7e860c7), archive parity (201e25f), package preview on reportable children (f600b6b), parent reference stripped from child projections (07e9935).
  • Integrated current main (713faaa) without conflicts as 216ae80. None of the 11 files this PR touches changed on main since its merge base d1414a7, so the merge brings no interaction with newer main work.
  • On the merged tree: bookkeeping API 24, accountant report 11, archive 5, credit notes 4, 12 reconcile suites (107) and 114 frontend bookkeeping/architecture cases pass; scale gate passes.
  • Exact head 216ae80: app and browser E2E checks SUCCESS; the CLI check is still queued behind the shared runner queue.

Still a separate decision: what to do with #314's unported parts (chunked v4 snapshots with CAS migration, the VAT category exemption, frontend VAT/format changes). Whichever of this PR and #524 lands second re-validates against the other's real head (shared files: bookkeepingAllocations.ts, api-bookkeeping.test.ts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant